<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use function fast\e;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }



    /**
     * 修改工作状态
     */
    public function workerover()
    {
        Db::name('user')->where(['worker'=>0])->update(['worker'=>1]);

        $liste=Db::name('workhour')->where(['status'=>0])->select();

        foreach ($liste as $key){
            $s=intval(time()-$key['startime']);
            $hour=ceil($s/3600);
            Db::name('workhour')
                ->where(['id'=>$key['id']])
                ->update(['endtime'=>time(),'status'=>1,'hour'=>$hour]);
        }


    }

    //自动完成上班的操作





    /**
     * 基础信息
     */
    public function getpublicinfo(){

        $info=Db::name('aa_seting')->find();


        $info['image']=cdnurl($info['image'],true);
        $info['logimage']=cdnurl($info['logimage'],true);



        $this->success('请求成功',$info);

    }

    public function getaddname(){

        $key='CQ5BZ-Q5GWI-RPWG6-573GV-WY6KQ-ARBI2';


        $location=$this->request->param('location');

        $url="https://apis.map.qq.com/ws/geocoder/v1/?location=".$location."&key=".$key."&get_poi=1";
//        $url="https://apis.map.qq.com/ws/geocoder/v1/?location=30.69015,104.05293&key=CQ5BZ-Q5GWI-RPWG6-573GV-WY6KQ-ARBI2";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);



        curl_close($ch);
        $response=json_decode($response,true);
//        print_r($response['result']['address']);


        $this->success('请求成功',$response['result']['address']);

    }

    /* 制度列表 */

    public function getrule(){

        $lists=Db::name('aa_rule')->select();


        $this->success('请求成功',$lists);


    }
    /* 制度详情 */
    public function getrulebyid(){
        $id=$this->request->param('id');
        $lists=Db::name('aa_rule')->where(['id'=>$id])->find();
        $this->success('请求成功',$lists);

    }

    /**
     * @return 本月开始结束 000
     */
    public function getnowtime(){

        $datea=date('Y-m').'-01';

        $dateb=date('Y-m-t', strtotime('today'));

        $this->success('请求成功',['a'=>$datea,'b'=>$dateb]);

    }

}
